<?php

declare(strict_types=1);
/**
 * This file is part of habo_new_media.
 *
 * @link     https://www.berlen.cn/
 * @contact  tech@berlen.cn
 * @license  http://gitlab.rehou.cn/habo/habo_new_media/-/blob/master/README.md
 */
namespace app\service\alioss;

use app\service\BaseService;
use OSS\OssClient;

class AliossService extends BaseService
{
    protected object $obj;

    protected string $bucket = '';

    public function __construct()
    {
        $keyId = env('alioss.access_key_id');
        $keySecret = env('alioss.access_key_secret');
        $endPoint = env('alioss.end_point');
        $this->bucket = env('alioss.bucket');
        $this->obj = new OssClient($keyId, $keySecret, $endPoint);
    }

    public function uploadFile(string $realPath = '', string $fileName = '')
    {
        // sha1加密 生成文件名 连接后缀
        // 执行阿里云上传
        $result = $this->obj->uploadFile($this->bucket, $fileName, $realPath);
        return $result['info']['url'];
    }
}
